package com.example.springbootsenior.ExceptionHandler.handler;

import com.example.springbootsenior.ExceptionHandler.AjaxResult;
import com.example.springbootsenior.ExceptionHandler.exception.LoginException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 登录异常
     */
    @ExceptionHandler(LoginException.class)
    public AjaxResult loginException(LoginException e) {
        log.error(e.getMessage() + "===>控制台", e);
        return AjaxResult.error(e.getMessage());
    }
}